//***********************************
// AuthorName:  龍
// CreateTime:  2023-08-24 09:25:46
// 备注:  
//***********************************

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;


/// <summary>
///  不能放 Drag ，scrollview 拖动 item  滑动失效
/// </summary>
public class EventTriggerLinstener : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler
{
    public delegate void EventTriggerDelegate(GameObject obj);
    public EventTriggerDelegate onClick;
    public EventTriggerDelegate onEnter;
    public EventTriggerDelegate onExit;
    public EventTriggerDelegate onDown;
    public EventTriggerDelegate onrUp;

    public static EventTriggerLinstener Get(GameObject obj)
    {
        if (obj == null)
            return null;

        return obj.GetOrAddComponent<EventTriggerLinstener>();
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        onClick?.Invoke(gameObject);
    }

    public void OnPointerEnter(PointerEventData eventData)
    {
        onEnter?.Invoke(gameObject);
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        onExit?.Invoke(gameObject);
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        onDown?.Invoke(gameObject);
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        onrUp?.Invoke(gameObject);
    }
}

public class EventTriggerLinstener_All : EventTrigger
{
    public delegate void EventTriggerDelegate(GameObject obj);

    public EventTriggerDelegate onBeginDrag;
    public EventTriggerDelegate onDrag;
    public EventTriggerDelegate onEndDrag;


    public static EventTriggerLinstener_All Get(GameObject obj)
    {
        if (obj == null)
            return null;

        return obj.GetOrAddComponent<EventTriggerLinstener_All>();
    }


    public override void OnBeginDrag(PointerEventData eventData)
    {
        //base.OnBeginDrag(eventData);
        onBeginDrag?.Invoke(gameObject);
    }

    public override void OnDrag(PointerEventData eventData)
    {
        //base.OnDrag(eventData);
        onDrag?.Invoke(gameObject);
    }

    public override void OnEndDrag(PointerEventData eventData)
    {
        //base.OnEndDrag(eventData);
        onEndDrag?.Invoke(gameObject);
    }


}

